package check

import (
	"fmt"
	"github.com/jinzhu/gorm"
	"time"
)

func updateCreated(scope *gorm.Scope) {

	if scope.HasError() {
		return
	}

	if !scope.HasColumn("CheckSum") {
		return
	}

	if IDField, ok := scope.FieldByName("id"); ok {
		if !IDField.IsBlank {
			return
		}
		id := IDField.Field.Int()
		fmt.Println(id)
		// TODO unfinished , because I don't known how to write it.
	}

}

func updateTimeStampForCreateCallback(scope *gorm.Scope) {
	if !scope.HasError() {
		nowTime := time.Now().Unix()
		if createTimeField, ok := scope.FieldByName("CreatedOn"); ok {
			if createTimeField.IsBlank {
				createTimeField.Set(nowTime)
			}
		}

		if modifyTimeField, ok := scope.FieldByName("ModifiedOn"); ok {
			if modifyTimeField.IsBlank {
				modifyTimeField.Set(nowTime)
			}
		}
	}
}
